package battleroom;

import com.jme3.app.state.AbstractAppState;
import com.jme3.input.InputManager;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.MouseAxisTrigger;
import com.jme3.math.Matrix3f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
 *
 * @author Adam
 * 
 * Controls mouse input, and what state it is in (i.e. pop up mouse pointer for GUI 
 * or move the camera)
 */
public class MouseState extends AbstractAppState{
    private static float sensitivity;
    private final CameraNode cam;
    private final Node playerNode;
    
    public MouseState(CameraNode cam, Node playerNode)
    {
        this.cam = cam;
        this.playerNode = playerNode;
        
        sensitivity = 1;
    }

    public void setUpMouseListener(InputManager inputManager) {
        inputManager.addMapping("mouse_x_right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
        inputManager.addMapping("mouse_x_left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
        inputManager.addMapping("mouse_y_up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
        inputManager.addMapping("mouse_y_down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        
        inputManager.addListener(mouseListener, "mouse_x_right");
        inputManager.addListener(mouseListener, "mouse_x_left");
        inputManager.addListener(mouseListener, "mouse_y_up");
        inputManager.addListener(mouseListener, "mouse_y_down");
        
        inputManager.setCursorVisible(false);
    }
    
    private AnalogListener mouseListener = new AnalogListener() {
        public void onAnalog(String name, float value, float tpf) {
            /*PlayerControl phys = playerNode.getControl(PlayerControl.class);
            
            float vX, vY;
            
            if (name.equals("mouse_x_right"))
            {
                vY = -value*sensitivity;
            }else{
                vY = 0;
            }
            
            
            if (name.equals("mouse_x_left"))
            {
                vY += value*sensitivity;
            }else{
                vY += 0;
            }
            
            if (name.equals("mouse_y_up"))
            {
                vX = -value*sensitivity;
            }else{
                vX = 0;
            }
            
            if (name.equals("mouse_y_down"))
            {
                vX += value*sensitivity;
            }else{
                vX += 0;
            }
            
            Quaternion newRot = playerNode.getLocalRotation().mult(new Quaternion(vX, vY, 0, 1f));
            phys.setPhysicsRotation(newRot);
            */
        }
    };
    
    
}
